package com.eascs.message.dao;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.eascs.admin.common.dao.BaseO2oDao;
import com.eascs.common.util.StringUtil;
import com.eascs.message.entiy.O2OMessage;

@Repository
public class O2OMessageDao extends BaseO2oDao{
	
	public boolean isExist(String type,String relevanceId){
		StringBuilder checksql = new StringBuilder();
		checksql.append("select * from o2o_message where 1=1 ");
		if(StringUtil.isNotBlank(type)){
			checksql.append(" and message_type = ? ");
		}
		if(StringUtil.isNotBlank(relevanceId)){
			checksql.append(" and relevance_id = ? ");
		}
		List<O2OMessage> list = o2oJdbcSession.findEntitys(checksql.toString(), O2OMessage.class,type,relevanceId);
		if(list.size()>0){
			return true;
		}else{
			return false;
		}
	}
	
	@Transactional(transactionManager = "o2oTransactionManager")
	public void saveEntity(Object entity) {
		o2oJdbcSession.insert(entity);
	}
}
